Question 1: Text on Mouse Over Event
#Load the PD Data
##counties shapefile
if(file.exists("cs.RData")==FALSE){
cs<-counties(year=2010)
save(cs,file="cs.RData")
}else{
load("cs.Rdata")
}
#Loading in the Census FIPS codes.
data("fips_codes")
#I will use where I am spending Thanksgiving, Louisiana
states_list<-c("LA")
## Filter fips code to get just those states
fips_codes<-fips_codes%>%group_by(state)%>%summarize(fips_code=first(state_code))
fips_list<-fips_codes%>%filter(state%in%states_list)
fips_list<-fips_list$fips_code
## Switch names to lower case
names(cs)<-tolower(names(cs))
## subset to state list
cs<-cs[cs$statefp%in%c(fips_list), ]## Just states we want
##subset county dataset to be just college grads and county name
pd_sub<-pd%>%select(fips,coll_grad_pc,median_hh_inc,county)%>%filter(grepl(states_list,county))
## Join the two datasets
cs<-geo_join(cs,pd_sub,"geoid10","fips")
pal<-colorNumeric(
palette="YlGnBu",
domain=cs$coll_grad_pc
)
#Data Popup
popup<-paste0(cs$county,
"<br>",
"Percent College Graduates= ",
cs$coll_grad_pc,
"<br",
"Median Household Income= ",
prettyNum(cs$median_hh_inc,big.mark=",")
)
#Draw the Map
map<-leaflet()%>%
addProviderTiles("CartoDB.Positron")%>%
addPolygons(data=cs,
fillColor=~pal(coll_grad_pc),
color="#b2aeae",
fillOpacity = .7,
weight=1,
smoothFactor = .2,
popup=popup
)%>%
addLegend(pal=pal,
values=cs$coll_grad_pc,
position="bottomright",
title="Percent College Graduates",
labFormat=labelFormat(suffix="%"))
map
saveWidget(widget=map,file="county_map.html")